package sdu.icat.ltp.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.bson.Document;

import sdu.icat.ltp.persistant.AbstractPersistant;
import sdu.icat.ltp.persistant.MongoPersistant;
import sdu.icat.ltp.tool.ArticleConfig;

/**
 * 输出服务
 * @author ljh_2015
 *
 */
public class ApiOutService {

    private final AbstractPersistant abPersistant = new MongoPersistant();
    
    /**
     * 根据参数获取
     * @param bookid
     * @param chapter_title
     * @param paragraphsort
     * @return
     */
    public List<Document> getAllArticles(int bookid,String chapter_title,int paragraphsort) {
	Map<String,String> params = new HashMap<>();
	params.put(ArticleConfig.bookid, "bookid_"+bookid);
	params.put(ArticleConfig.chapter_title, chapter_title);
	params.put(ArticleConfig.paragraph, String.valueOf(paragraphsort));
	return abPersistant.findArticleChapters(params);
    }
    
    public List<Document> listSimpleView() {
	return abPersistant.listView();
    }
    
    public Document findMyText(String text) {
	return abPersistant.findDocument(text);
    }
    
    public List<Document> listRegexText(String key) {
	return abPersistant.findDocuments(key);
    }
    
    public List<Document> listArticle(String title) {
	return abPersistant.findDocumentWithTitle(title);
    }
}
